home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / utils / misc / ace / ace-2.0.lha / PRGS.lha / Misc / linkedlist.b < prev   
Text File  |  1994-01-10  |  796b  |  49 lines

  1. '..a linked list using ACE structures.
  2.  
  3. deflng a-z
  4.  
  5. struct node
  6.  string nm
  7.  address nxt
  8. end struct
  9.  
  10. declare struct node *head,*new.item,*curr,*temp
  11.  
  12. sub make.node
  13.  make.node = Alloc(sizeof(node),2)
  14. end sub
  15.  
  16. '..create head of list
  17. head = make.node
  18. if head = NULL then 
  19.   print "head node can't be allocated!" 
  20.   stop
  21. end if
  22.  
  23. head->nm = ""
  24. head->nxt = NULL
  25. curr = head
  26.  
  27. '..create list  
  28. repeat
  29.  input "type a name (or QUIT): ";x$
  30.  new.item = make.node
  31.  if new.item <> NULL then
  32.   new.item->nm = x$
  33.   new.item->nxt = NULL
  34.   
  35.   curr->nxt = new.item
  36.   curr = curr->nxt
  37.  else
  38.   print "new node can't be allocated!" 
  39.  end if
  40. until ucase$(x$) = "QUIT" or new.item=NULL
  41.  
  42. '..traverse list
  43. cls
  44. curr = head->nxt
  45. while curr <> NULL
  46.   if ucase$(curr->nm) <> "QUIT"  then print curr->nm
  47.   curr = curr->nxt
  48. wend
  49.